//    Copyright (C) Kherty.  All rights reserved.
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public class StringValue : ValueBase
    {
        private StringReference _parent;
        private string _value;

        public StringValue()
        {
        }

        public StringValue(int index, string val)
        {
            Index = index;
            Value = val;
        }

        public StringReference Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }

        public string Value
        {
            get { return _value; }
            set
            {
                _value = value;
                notifyPropertyChanged("Value");
            }
        }

        internal override void ReadXmlCore(ReadContext context)
        {
            using (var c = context.Read("pt"))
            {
                Index = c.GetInteger("idx");
                Value = c.ReadElementString("v");
            }
        }

        internal override void WriteXmlCore(WriteContext context)
        {
            using (WriteContext c = context.Write("pt"))
            {
                c.SetInteger("idx", Index);
                c.WriteElementString("v", Value);
            }
        }
    }
}